package org.example.sep13.Mapper;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Select;
import org.example.sep13.entity.Card;
import org.example.sep13.entity.Student;


import java.util.List;

@Mapper
public interface StudentMapper {

    @Result(property = "card",column = "non", one = @One(select = "org.example.sep13.dao.StudentMapper.getCardByNumber"))
    @Select("select * from students where name like concat('%',#{name}, '%')")
    List<Student> getStuByName(String name);

    @Select("select * from card where cardNo = #{number}")
    Card getCardByNumber(String number);

    @Select({
            "<script>",
            "select * from students where 1=1",
            "<if test='name != null'>",
            "and name = #{name}",
            "</if>",
            "<if test='number != null'>",
            "and non = #{number}",
            "</if>",
            "</script>"
    })
    List<Student> getStuByNameOrNo(String name,String number);
}
